﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;
using ZhouYu.NewWorld.BLL.IService;
using ZhouYu.NewWorld.Model;
using ZhouYu.NewWorld.ViewModel;
using ZhouYu.NewWorld.Web.Models;

namespace ZhouYu.NewWorld.Web.Controllers
{
    public class WebcolumnController : Controller
    {
        //注入
        private IWebcolumnService _webcolumnService;
        public WebcolumnController(IWebcolumnService webcolumnService)
        {
            _webcolumnService = webcolumnService;
        }


        // GET: Webcolumn
        /// <summary>
        /// 获取菜单列表
        /// </summary>
        /// <returns></returns>
        public JsonResult GetWebcolumnList(int page, int limit, string WebColumn_Name)
        {
            //创建返回结果对象
            ResponseResult responseResult = new ResponseResult();
            //定义表数据总数变量
            int count = 0;
            Expression<Func<Webcolumn, bool>> whereLambda = a => true;
            //模糊查询
            if (WebColumn_Name != string.Empty && WebColumn_Name != null)
            {
                whereLambda = a => a.WebColumn_Name.Contains(WebColumn_Name);
            }
            Expression<Func<Webcolumn, int>> orderbyLambda = a => a.WebColumn_Id;
            List<Webcolumn> result =  _webcolumnService.QueryPageList(page, limit, whereLambda, orderbyLambda, out count);
            //赋值
            responseResult.code = 0;
            responseResult.msg = string.Empty;
            responseResult.data = result;
            responseResult.count = count;
            return Json(responseResult, JsonRequestBehavior.AllowGet);//JsonRequestBehavior.AllowGet参数：防止数据不安全泄露;
        }
        /// <summary>
        /// 单个删除
        /// </summary>
        /// <returns></returns>
        public JsonResult DeleteWebcolumn(Webcolumn webcolumn)
        {
            //创建返回结果对象
            ResponseResult responseResult = new ResponseResult();
            //调用删除方法
            responseResult.Success = _webcolumnService.Delete(webcolumn);
            return Json(responseResult,JsonRequestBehavior.AllowGet);//JsonRequestBehavior.AllowGet参数：防止数据不安全泄露;
    }
        /// <summary>
        /// 根据Id 删除多个实体
        /// </summary>
        /// <param name="ids"></param>
        /// <returns></returns>
        public JsonResult BatchDelete(string Id)
        {
            //string转换string[]数据
            string[] strArray = Id.Split(',');
            int[] iNums;
            //string[]转换int[]
            iNums = Array.ConvertAll(strArray, int.Parse);
            //创建返回结果对象 
            ResponseResult responseResult = new ResponseResult();
            //调用批量删除方法
            responseResult.Success = _webcolumnService.BatchDeleteById(iNums);
            return Json(responseResult,JsonRequestBehavior.AllowGet);//JsonRequestBehavior.AllowGet参数：防止数据不安全泄露; 
        }

        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="website"></param>
        /// <returns></returns>
        public JsonResult UpdateWebcolumn(Webcolumn webcolumn)
        {
            //创建返回结果对象
            ResponseResult responseResult = new ResponseResult();
            //获取当前时间
            webcolumn.WebColumn_UpdateTime = DateTime.Now;
            //调用修改方法
            responseResult.Success = _webcolumnService.Update(webcolumn);
            return Json(responseResult,JsonRequestBehavior.AllowGet);//JsonRequestBehavior.AllowGet参数：防止数据不安全泄露;
        }

        /// <summary>
        /// 判断是否已有
        /// </summary>
        public JsonResult Judge(string WebColumn_Name)
        {
            //创建返回结果对象
            ResponseResult responseResult = new ResponseResult();
            responseResult.Success = _webcolumnService.Judge(WebColumn_Name);
            return Json(responseResult,JsonRequestBehavior.AllowGet);//JsonRequestBehavior.AllowGet参数：防止数据不安全泄露;
        }
        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="website"></param>
        /// <returns></returns>
        public JsonResult AddWebcolumn(Webcolumn web)
        {
            //创建返回结果对象
            ResponseResult responseResult = new ResponseResult();
            //获取当前时间
            web.WebColumn_CreateTime = DateTime.Now;
            //调用添加方法
            responseResult.Success = _webcolumnService.Add(web);
            return Json(responseResult, JsonRequestBehavior.AllowGet);//JsonRequestBehavior.AllowGet参数：防止数据不安全泄露;
        }
    }
}